//
//  BSSTeacherSexTableViewCell.m
//  PreschoolEducation
//
//  Created by 李传铎 on 2020/11/15.
//  Copyright © 2020 李传铎. All rights reserved.
//

#import "BSSTeacherSexTableViewCell.h"

@implementation BSSTeacherSexTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.contentView.backgroundColor = [UIColor clearColor];
        [self createUI];
        [self layoutUI];
    }
    return self;
}

- (void)createUI {
    [self.contentView addSubview:self.titleLab];
    [self.contentView addSubview:self.line];
    [self.contentView addSubview:self.boyBtn];
    [self.contentView addSubview:self.girlBtn];
}

- (void)layoutUI {

    [_titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(__kSize(22));
        make.top.mas_equalTo(__kSize(12));
    }];
  
    [_line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(_titleLab.mas_bottom).mas_offset(__kSize(12));
        make.left.mas_equalTo(__kSize(22));
        make.right.mas_equalTo(__kSize(- 22));
        make.height.mas_equalTo(0.5);
        make.bottom.mas_equalTo(self.contentView);
    }];
    [_boyBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(97);
        make.width.mas_equalTo(60);
        make.height.mas_equalTo(25);
        make.centerY.mas_equalTo(_titleLab.mas_centerY);
    }];
    
    [_girlBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(_boyBtn.mas_right).offset(15);
        make.width.mas_equalTo(60);
        make.height.mas_equalTo(25);
        make.centerY.mas_equalTo(_titleLab.mas_centerY);
    }];
}
- (void)setModel:(BSSEnterpriseCertificationModel *)model{
    _model = model;
    if ([model.value isEqualToString:@"男"]) {
        self.boyBtn.selected = YES;
        self.girlBtn.selected = NO;
    }else if ([model.value isEqualToString:@"女"]){
        self.boyBtn.selected = NO;
        self.girlBtn.selected = YES;
    }else{
        self.boyBtn.selected = NO;
        self.boyBtn.selected = NO;
    }
}
- (void)boyClick:(UIButton *)sender{
    sender.selected = !sender.selected;
    _girlBtn.selected = NO;
    if (sender.selected) {
        self.model.value = @"男";
    }else{
        self.model.value = @"";
    }
}
- (void)girlClick:(UIButton *)sender{
    sender.selected = !sender.selected;
    _boyBtn.selected = NO;
    if (sender.selected) {
        self.model.value = @"女";
    }else{
        self.model.value = @"";
    }
}
#pragma mark - action

#pragma mark - setter & getter

- (UILabel *)titleLab {
    if (!_titleLab) {
        _titleLab = [UILabel new];
        _titleLab.textColor = __kColor(51, 51, 51);
        _titleLab.font = fontCount(14);
    }
    return _titleLab;
}
- (UIButton *)boyBtn{
    if (!_boyBtn) {
        _boyBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_boyBtn setTitle:@"男" forState:0];
        _boyBtn.titleLabel.font = fontCount(14);
        [_boyBtn setTitleColor:colorCode(@"999999") forState:0];
        [_boyBtn setImage:imageNameStr(@"ic_chosse_off") forState:0];
        [_boyBtn setImage:imageNameStr(@"ic_chosse_on") forState:UIControlStateSelected];
        [_boyBtn addTarget:self action:@selector(boyClick:) forControlEvents:UIControlEventTouchUpInside];
        _boyBtn.imageEdgeInsets = UIEdgeInsetsMake(0, -10, 0, 0);
        _boyBtn.titleEdgeInsets = UIEdgeInsetsMake(0, 0, 0,-5);
    }
    return _boyBtn;
}
- (UIButton *)girlBtn{
    if (!_girlBtn) {
        _girlBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_girlBtn setTitle:@"女" forState:0];
        _girlBtn.titleLabel.font = fontCount(14);
        [_girlBtn setTitleColor:colorCode(@"999999") forState:0];
        [_girlBtn setImage:imageNameStr(@"ic_chosse_off") forState:0];
        [_girlBtn setImage:imageNameStr(@"ic_chosse_on") forState:UIControlStateSelected];
        [_girlBtn addTarget:self action:@selector(girlClick:) forControlEvents:UIControlEventTouchUpInside];
        _girlBtn.imageEdgeInsets = UIEdgeInsetsMake(0, -10, 0, 0);
        _girlBtn.titleEdgeInsets = UIEdgeInsetsMake(0, 0, 0,-5);
    }
    return _girlBtn;
}
- (UIView *)line {
    if (!_line) {
        _line = [UIView new];
        _line.backgroundColor = __kColor(238, 238, 238);
    }
    return _line;
}
- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
